# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

pkgname='vcspull'
pkgver=1.20.2
pkgrel=2
pkgdesc='Synchronize projects via yaml/json manifest. Built using `libvcs`'
arch=('any')
url='https://vcspull.git-pull.com/'
license=('MIT')
depends=('python' 'python-colorama' 'python-libvcs' 'python-shtab' 'python-yaml')
makedepends=('python-build' 'python-installer' 'python-poetry-core' 'python-typing_extensions')
checkdepends=('git' 'python-pytest' 'python-pytest-rerunfailures')
optdepends=(
  'bash-completion: for command line completion in bash'
)
source=("https://github.com/vcs-python/vcspull/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('f85ec9003e225482f8349cb1bf902b935a891230bd657a3f79412a40e1b8348a002b33e27a228b0eff11407f8f3e8c01a6f2cd5ebc44c808ad16f2fc339403b9')
b2sums=('8f6a4e931ddc73ef6d34b31f851fa7195a4b7b4354d9418a1a65f46ecdb38e99398a39b36c49f51617aa5978fc66fbcec76e870d0f2f985d76b3ecb16a5c9665')

build() {
  cd  "${pkgname}-${pkgver}"

  local _site_packages="$(python -c "import site; print(site.getsitepackages()[0])")"

  python -m build --wheel --skip-dependency-check --no-isolation
  python -m installer --destdir=tmp_install dist/*.whl

  export PYTHONPATH="tmp_install${_site_packages}:${PYTHONPATH}"
}

check() {
  cd  "${pkgname}-${pkgver}"

  pytest -vv tests
}

package() {
  cd  "${pkgname}-${pkgver}"

  cp --archive --verbose tmp_install/* "${pkgdir}"

  install --verbose --directory --mode=0755 \
      "${pkgdir}/usr/share/bash-completion/completions" \
      "${pkgdir}/usr/share/zsh/site-functions" \
      "${pkgdir}/etc/profile.d"

  shtab --shell=bash --error-unimportable vcspull.cli.create_parser > "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  shtab --shell=zsh --error-unimportable vcspull.cli.create_parser > "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
  shtab --shell=tcsh --error-unimportable vcspull.cli.create_parser > "${pkgdir}/etc/profile.d/${pkgname}.completion.csh"

  install --verbose -D --mode=0644 LICENSE --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
  install --verbose -D --mode=0644 *.md CHANGES MIGRATION --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
  install --verbose -D --mode=0644 examples/* --target-directory "${pkgdir}/usr/share/doc/${pkgname}/examples"
}

# vim: tabstop=2 shiftwidth=2 expandtab:
